#region Using directives

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

using FighterChessEngine.FC_Player;
using FighterChessEngine.Enum;

#endregion

namespace FighterChess
{
    /// <summary>
    /// Summary description for frmStart.
    /// </summary>
    public class frmStart : System.Windows.Forms.Form
    {
        private Label label1;
        private TextBox txtP1Name;
        private Label label2;
        private TextBox txtP2Name;
        private Panel panel1;
        private RadioButton rbtnP2GoFirst;
        private RadioButton rbtnP1GoFirst;
        private Label label3;
        private Button btnOK;
        private Button btnQuit;
        private Label label4;

        public frmStart()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.txtP1Name = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtP2Name = new System.Windows.Forms.TextBox();
            this.panel1 = new System.Windows.Forms.Panel();
            this.rbtnP1GoFirst = new System.Windows.Forms.RadioButton();
            this.rbtnP2GoFirst = new System.Windows.Forms.RadioButton();
            this.label3 = new System.Windows.Forms.Label();
            this.btnOK = new System.Windows.Forms.Button();
            this.label4 = new System.Windows.Forms.Label();
            this.btnQuit = new System.Windows.Forms.Button();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(7, 32);
            this.label1.Size = new System.Drawing.Size(62, 20);
            this.label1.Text = "Player 1:";
            // 
            // txtP1Name
            // 
            this.txtP1Name.Location = new System.Drawing.Point(87, 32);
            this.txtP1Name.Size = new System.Drawing.Size(139, 21);
            this.txtP1Name.TextChanged += new System.EventHandler(this.txtP1Name_TextChanged);
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(7, 89);
            this.label2.Size = new System.Drawing.Size(62, 20);
            this.label2.Text = "Player 2:";
            // 
            // txtP2Name
            // 
            this.txtP2Name.Location = new System.Drawing.Point(87, 89);
            this.txtP2Name.Size = new System.Drawing.Size(139, 21);
            this.txtP2Name.TextChanged += new System.EventHandler(this.txtP2Name_TextChanged);
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.rbtnP2GoFirst);
            this.panel1.Controls.Add(this.rbtnP1GoFirst);
            this.panel1.Location = new System.Drawing.Point(87, 157);
            this.panel1.Size = new System.Drawing.Size(139, 57);
            // 
            // rbtnP1GoFirst
            // 
            this.rbtnP1GoFirst.Checked = true;
            this.rbtnP1GoFirst.Location = new System.Drawing.Point(4, 4);
            this.rbtnP1GoFirst.Size = new System.Drawing.Size(100, 20);
            this.rbtnP1GoFirst.Text = "Player1";
            // 
            // rbtnP2GoFirst
            // 
            this.rbtnP2GoFirst.Location = new System.Drawing.Point(4, 31);
            this.rbtnP2GoFirst.Size = new System.Drawing.Size(100, 20);
            this.rbtnP2GoFirst.Text = "Player2";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(7, 157);
            this.label3.Size = new System.Drawing.Size(74, 20);
            this.label3.Text = "First hand :";
            // 
            // btnOK
            // 
            this.btnOK.Location = new System.Drawing.Point(154, 258);
            this.btnOK.Size = new System.Drawing.Size(72, 20);
            this.btnOK.Text = "Play!";
            this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(62, 61);
            this.label4.Size = new System.Drawing.Size(100, 20);
            this.label4.Text = "vs";
            // 
            // btnQuit
            // 
            this.btnQuit.Location = new System.Drawing.Point(76, 258);
            this.btnQuit.Size = new System.Drawing.Size(72, 20);
            this.btnQuit.Text = "Quit";
            this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click);
            // 
            // frmStart
            // 
            this.ClientSize = new System.Drawing.Size(240, 294);
            this.ControlBox = false;
            this.Controls.Add(this.btnQuit);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.txtP2Name);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtP1Name);
            this.Controls.Add(this.label1);
            this.MinimizeBox = false;
            this.Text = "Start game";
            this.Load += new System.EventHandler(this.frmStart_Load);

        }

        #endregion

        private void frmStart_Load(object sender, EventArgs e)
        {
            
        }

        private void txtP1Name_TextChanged(object sender, EventArgs e)
        {
            if (txtP1Name.Text == "")
                rbtnP1GoFirst.Text = "Player1";
            else
                rbtnP1GoFirst.Text = txtP1Name.Text;
        }

        private void txtP2Name_TextChanged(object sender, EventArgs e)
        {
            if (txtP2Name.Text == "")
                rbtnP2GoFirst.Text = "Player2";
            else
                rbtnP2GoFirst.Text = txtP2Name.Text;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {   
            Player p1 = new Player(
                txtP1Name.Text == "" ? "Player1" : txtP1Name.Text, 
                Owner.White);
            Player p2 = new Player(
                txtP2Name.Text == "" ? "Player2" : txtP2Name.Text, 
                Owner.Black);

            if (rbtnP1GoFirst.Checked)
                p1.Active = true;
            else if (rbtnP2GoFirst.Checked)
                p2.Active = true;

            frmMain frm = new frmMain(p1, p2);
            /*if (frm.ShowDialog() == DialogResult.Cancel)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Dispose();
                this.Close();
            }*/
            frm.Show();
            this.Close();
            this.Dispose();
        }

        private void btnQuit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
